home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1369.dms / var1369.adf / RSRead.Me < prev    next >
Text File  |  1992-09-02  |  63KB  |  1,075 lines

  1.  
  2.  
  3.              A DEMONSTRATION of the RSA ENCRYPTION ALGORITHM.
  4.              ================================================
  5.       
  6.            ####################################################
  7.            #                                                  #
  8.            #    The author of this demonstration disk is :    #
  9.            #                                                  #
  10.            #             Mr. N. Hensor                        #
  11.            #                86, Teignmouth Road               #
  12.            #                   London  NW2 - 4DX              #
  13.            #                                                  #   
  14.            #    THERE ARE SEVERAL INSECURE FEATURES TO THIS   # 
  15.            #  PACKAGE. ANYONE WISHING TO PURCHASE THE SECURE  #
  16.            #    VERSION, CONTACT ME AT THE ABOVE ADDRESS BY   #
  17.            #           MAIL IN THE FIRST INSTANCE.            #
  18.            #                                                  #         
  19.            #   I also have a wide range of modules for other  #
  20.            #        cryptographic algorithms available.       #
  21.            #    [In C and assembler (Mororola processors)]    #
  22.            #      and will write new modules as required.     #
  23.            #                                                  #
  24.            ####################################################
  25.             
  26.             #------------------------------------------------#
  27.             
  28.             This program will only run on Motorola 68020
  29.             processors ie Amiga 1200 systems. It will not run
  30.             on Motorola 68000 systems (Amiga 500/600/1000/2000)
  31.             
  32.             #------------------------------------------------#
  33.  
  34.    The Rivest-Shamir-Adleman encryption algorithm is one of several recently
  35. developed techniques for encryption which put immense security for
  36. telecommunications and file-archives within reach of the home computer user.
  37.  
  38.    This software was written starting with the following objectives:
  39.  
  40.    (a) The highest possible level of telecommunications security should be 
  41.          made available to the widest possible market.
  42.  
  43.    (b) Encryption speed considerations should not be allowed to intrude on
  44.          questions of encryption quality, but once a scheme had been 
  45.          decided upon, assembler routines would be used to obtain the best
  46.          possible speed.
  47.          
  48.    If you ask the question "What is the ultimate encryption method?", there
  49. is, and never will be, a clear cut answer. However if you draw up a list of
  50. say 10 candidates, then some of them are not suitable for use on
  51. micro-computers. Of the remaining half-dozen which are suitable,
  52. comparisons of security are difficult to arrive at. The RSA algorithm would
  53. be on everyones shortlist and provides immense security.
  54.  
  55.    This algorithm belongs to a class of encryption schemes known as 
  56. "Public-Key" encryption schemes. These schemes provide a simple solution to
  57. the age-old problem of key-distribution. The algorithm is particularly
  58. suited to ensure telecommunications security but can also be used for
  59. personal file security. A detailed discussion of the algorithm can be found
  60. in many reference books, but the next section contains a thumb-nail sketch
  61. of the method - see also the last section on 'Number Theory' for a more
  62. mathematical description. 
  63.  
  64. The Basics of the RSA algorithm
  65. ===============================
  66.    The algorithm makes heavy use of raising integers to an integer power
  67. and then reducing the result using an integer modulus. A brief review of 
  68. these operations is given at the end of this report, but a detail knowledge
  69. of number theory is not necessary to use the R.S.A. algorithm. 
  70. [All numbers are integers from this point on unless stated otherwise]
  71.          
  72.    The RSA algorithm makes use of the following steps for encryption:
  73.    (a) The message is broken into blocks of numbers.
  74.    (b) Each number is raised to a power {e} (the encryption exponent) and
  75.          reduced relative to a composite modulus {N} = p.q. (p,q prime nos)
  76.    (c) (Optional) The resulting number is changed into text - solely for
  77.          the purpose of transmission if a modem or hard copy print-out 
  78.          is to be used for transmission.         
  79.  
  80.    The resulting text can be restored to its original state by:
  81.    (a) similar to (c) above.
  82.    (c) Each number is raised to a power {d} (the decryption exponent)
  83.          and reduced relative to the same modulus {N} as above.
  84.    (d) The resulting number is changed back to text.
  85.    
  86.    The results of these operations depend solely on the 3 numbers {N}, {d}
  87. and {e}. Of these {N} and {e} are published - possibly by use of printed
  88. lists, possibly by use of a mailed floppy disk or any other convenient
  89. means. It is presumed at this point that a potential eavesdropper obtains
  90. copies of these numbers. Hence no security is provided by {N} and {e} and
  91. all security is provided by keeping {d} secret. This number must be kept
  92. locked away and if ever it is suspected that {d} has been compromised, then
  93. a new set of numbers {N}, {e}, {d} found, the new {N}, {e} published and
  94. the new {d} locked away - in short send any potential eavesdropper back to
  95. square 1. There are billions of billions ...........of billions of 
  96. satisfactory numbers (more than the number of molecules in the whole of the
  97. universe) and this software package enables them to be found.
  98.    It might be argued that since {N} and {e} are openly published, then it
  99. might be possible for a potential eavesdropper to obtain a {d} by analysis
  100. of {N} and {e}. This is possible if {N} (which is a product of 2 prime
  101. numbers) can be factorized or if modular-logarithms can be found.
  102. Factorization and modular-logarithms are a well known "hard" numerical
  103. problems, and we shall briefly discuss factorisation below.
  104. (modular-logarithms are just as hard)
  105.  
  106.    Factorization algorithms do exist - they are just not very good. The
  107. best available (the Number Field Sieve 1989) has a run time proportional to
  108. a constant raised to a power of (n^(1/3). log(n)^(2/3))  where n is the 
  109. size of the number to be factorized in either decimal digits or binary bits.
  110. To appreciate the significance of this formula, let us consider some
  111. published results concerning factoring times :
  112.   (1) A 116 digit composite was factorised [EUROCRYPT 1990] by several
  113. computers (total power about 400 MIPS) in 12 months.
  114.   (2) C. Pomerance sketched out (in 1988) the design of a specialised 
  115. factoring computer built from custom VLSI chips costing $10,000,000. This
  116. machine would be roughly 16,000 MIPS (or 16 GIPS). (National intelligence
  117. agencies can be expected to possess such machines.) This machine was built
  118. to work an older factoring algorithm known as the quadratic sieve algorithm.
  119.   (3) Computing power increases by about a factor of 16 per decade and costs
  120. fall by a factor of about 100 per decade. 
  121.   
  122.      Using these figures, we can estimate factorization times for a 16 GIPS
  123. (year 1990) machine working the number-field-sieve algorithm as :
  124.  
  125.    Decimal Digits |Approximate Factorization Time at year|
  126.        in {N}     |   1990    |    2000    |    2010     |
  127.    =======================================================
  128.         100       |    3 days |   4.5 hrs  |   15 mins   |
  129.         150       |   56 days |   3.1 days |  4.6 hrs    |
  130.         200       |   1.2 yrs |  31.6 days |  2.0 days   |
  131.         300       |  48.7 yrs |   3.1 yrs  | 70.7 days   |
  132.         400       | 866   yrs |    54 yrs  |  3.4 yrs    |
  133.         500       | forget it |   688 yrs  |   43 yrs    |
  134.    -------------------------------------------------------
  135.  
  136.    The column for a year 2000 machine refers to a 256 GIPS machine and for
  137. 2010, a 4096 GIPS machine. [Want to be rich and famous? Want to lie in the
  138. Caribbean sun wondering where your next £100m is coming from? - Easy - just
  139. find a method of factoring large composites!]
  140.    
  141.    The point of this table is that factorization time climbs so steeply that
  142. any opponent just has to give up at some point. If he can factor 200 digit
  143. composites then use 300 digit composites or 400 digits and so on. All of
  144. this would be academic if it were equally hard to put a suitable composite
  145. together in the first place. In fact your humble Amiga 1200 can find 
  146. suitable 500-digit composites in about 5.25 hrs of running time which
  147. all the computers on the planet, working in collusion, would take centuries
  148. to split apart.
  149.    From the point of view of users, the table is revealing in other ways. 
  150. It should be clear that security can be set at any desired level with this
  151. algorithm, in proportion to the risks attendant upon disclosure. If large
  152. sums of money or even life and limb are at risk, then choose an {N} with
  153. upwards of 300 digits and change these parameters regularly. On the other
  154. hand a personal diary might be satisfactory with a 100 digit {N} and not 
  155. bother changing it at all - a 'mere' 100 MIPS machine would still take 1.5
  156. years to factor it!
  157.    The drawback with choosing very large {N} values is the speed of
  158. encryption. Very roughly the speed of encryption (chars/sec)falls off 
  159. nearly as the square of the number of digits in {N}. With an {N} of about
  160. 100 digits, this software encrypts/decrypts at about 1000 chars/min and 
  161. with an {N} of 500 digits, encryption rate falls to about 100 chars/min.
  162.    Clearly the size of {N} has to be carefully considered before selection.
  163. In the software you will be asked to set a value for the size of {N} in
  164. binary bits. It takes about 3.32 binary bits to represent each decimal digit
  165. and hence if an {N} of 300 digits is desired, this corresponds to about
  166. 1000 binary bits.
  167.       
  168.        FOR THIS DEMONSTRATION SYSTEM, THE MAXIMUM SIZE OF {N} IS
  169.                LIMITED TO 350 BITS (105 DECIMAL DIGITS).
  170.  
  171. Getting Started with the Software
  172. =================================
  173.    The software package is a collection of modules and movement from module
  174. to module is controlled by the special function keys. F10 is always an exit
  175. key and the lower number keys are used for selections.
  176.    At the top level, F1-F4 will be the most used keys. Pressing F3 and F4 
  177. permit access to various housekeeping utilities. As a first step press F3
  178. to go into the ENTER/EXAMINE TEXT section. A list of three  utilities will 
  179. then appear. Let us first check that the printer is correctly set up.
  180.  
  181.    This demonstration software package assumes:
  182.    (a) The printer is connected to the parallel port.
  183.    (b) The printer DIP switches are set to receive English symbols (ISO 4)
  184.          and will insert a carriage-return when it receives a new-line(0x0A)
  185.          command. The Amiga uses a new-line command on its own as a line
  186.          terminator.
  187.    (c) This software package requires the printer to act in a similar way
  188.          to an old fashioned teletype in that visual access is required to
  189.          each line as it is printed. Lasers and inkjets do not usually 
  190.          permit this and paper consumption with these will be excessive if
  191.          it is necessary to keep pressing 'form-feed'. 
  192.          The ideal printer is a daisy-wheel type printing to fanfold paper
  193.          but a dot-matrix type is also satisfactory.
  194.  
  195.    Press now F3 which will transfer any disk-file to the printer after you
  196. have entered the file AmigaDOS path-name. If the outcome is not
  197. satisfactory, then the DIP switches on the printer may have to be adjusted
  198. and F3 tried again until success has been obtained.
  199.    As a second test of the printer, let us use the silent-screen facility.
  200. In this software package, the message which has to remain secure is always
  201. kept off the VDU. VDU's are insecure in that it is possible to capture the
  202. electromagnetic emissions and reconstitute the display using a nearby 
  203. receiver. Even a printer is moderately insecure since cases of shredded 
  204. paper being reconstituted have been revealed. (It is also possible that the
  205. acoustic emissions from a dot-matrix printer could be processed to obtain
  206. the characters being printed.) However if the printer output
  207. is incinerated and the ash pulverised, then a printer will be secure. By
  208. default, the silent-screen message entry facility (F1) will not echo input
  209. to the printer; it will pass it straight to a disk file 
  210. "RS:RSpublic/silent.txt". However it is possible to change this by 
  211. altering a global variable in section F4, so exit F3, go into F4, then
  212. press F1 now to enter the 'RESET GLOBAL VARIABLES' section. The 5 global 
  213. variables "nRabin","FileStnData","SStoprinter","Adapt" and "CharSet" can
  214. now be changed. Press now the following keys in order:
  215.     
  216.       7,<enter>,1,<enter>,1,<enter>,TRUE,<enter>,1,<enter> and then F1 
  217.          signalling all OK, and F1 again to indicate session-use only.
  218.     
  219.    The significance of these variables will be explained shortly, but for 
  220. the moment setting "SStoprin" to 1 will force section F3-F1 to echo your
  221. input line-by-line to the printer. (These variables remain in their
  222. set-state until section F1 is re-entered or until the Amiga is reset). 
  223.    Now we are ready to enter the silent screen section so press F3,F1.
  224.    You will be given the option of exiting the section but press F1 to
  225. proceed. (These early-exit options are included to provide a way out for
  226. anyone making a wrong key-press)
  227.    Enter now any line of text. Note that the cursor moves but that no text 
  228. appears on the VDU. When you press <enter>, the line is output to the 
  229. printer and can be inspected together with a chance to accept/reject it. In
  230. this way a message can be built up line by line until a zero-length line is
  231. input signifying the end of text entry. Before you do this make sure that
  232. 1 of your lines contains a "£" sign and check that your printer
  233. correctly reproduces it. If it does not, then your printer DIP switches
  234. will need adjusting until it is set to receive English symbols.
  235.     [You may find difficulty in getting your printer to print # (0x23)
  236.      and £ (0xa3) at the same time. Some printers (Windows compatibles,
  237.      ECMA-94 character set, etc) can do this; others will only print
  238.      one or the other : Try entering £#  then by changing your printer
  239.      switches to English or USA the results may be ## or ££. If this
  240.      happens, then make a decision as to which you prefer, set the
  241.      printer to suit and avoid the use of the non-functioning key]
  242.    When you have completed line entry, you might re-enter section F3 to
  243. examine the complete text that you have just entered.
  244.    The only section of F3 not discussed so far is the file destruction
  245. section (F2). In the full system a U.S. Dept. of Defence recommendation for
  246. erasure of files on magnetic media is used. In brief the file is
  247. overwritten 3 times, then declared empty. IN THIS DEMONSTRATION SYSTEM, THE
  248. FILE DESTRUCTION ROUTINE HAS BEEN SHORTED OUT, LEAVING YOUR FLOPPY DISKS IN
  249. AN INSECURE STATE. [THE AmigaDOS 'DELETE' FUNCTION IS INSECURE - it destroys
  250. pointers but not the file itself] You can still enter F2 to check it out,
  251. BUT NO FILE-DESTRUCTION WILL TAKE PLACE.
  252.    
  253.    Let us now consider the problem of finding prime numbers. Recall that
  254. {N} has to be the product of 2 (possibly more) prime numbers. Several other
  255. modern cryptographic techniques make use of the properties of primes, and
  256. all these need to be able to find new primes at the drop of a hat. 
  257. Section F4-F5 permits direct access to the prime number seeking software.
  258. This section is a stand alone module not related to the main purpose of the
  259. package. It is included to satisfy any ultra-suspicious customer who might
  260. suspect that this package is using trickery in finding a set of R.S.A.
  261. parameters. For the moment all we need to know is that these modules are the
  262. same ones used by F6 (the R.S.A. parameter set-up section)  and it is easier
  263. to get familiar with the prime number seeking software using F5 than F6.
  264. So press F5 now. Press F1 to get past the early-exit check and then
  265. start to enter your "job-file". Enter the following numbers:
  266.  
  267.       250  <enter>  240  <enter>  1  <enter>  1  <enter>
  268.       250  <enter>  240  <enter>  2  <enter>  1  <enter>
  269.       250  <enter>  240  <enter>  3  <enter>  1  <enter>      
  270.  
  271.    Then press F1 to approve your input. This job-file will find one prime
  272. number of each type supported, each of moderate size. (250-240 bits) There
  273. is no point in seeking large primes on this familiarisation tour, since all
  274. that happens is that the machine takes longer and longer.
  275. [ON THIS DEMONSTRATION DISK ONLY PRIMES SMALLER THAN 300 BITS CAN BE FOUND]
  276. No further input is needed so sit back and watch the machine work.
  277.    The software uses a random number generator to set up a random number of
  278. the required size on the line of integers to act as a starting 'seed' for
  279. the search. Blocks of numbers ( 1block = 768 consecutive numbers throughout
  280. this package) are now searched for primes. Searching is a two stage process.
  281. The first stage eliminates all numbers divisible by all the small primes
  282. up to a variable limit. When this stage is complete, there are usuallly 
  283. about 30-40 numbers remaining which might still be prime. The remaining 
  284. candidates are then tested using Rabin's algorithm.
  285. Rabin's algorithm takes as input 2 numbers:
  286.    (a) The candidate number to be tested for primality.
  287.    (b) A random integer called a "witness" used in the test.
  288. It has two possible outcomes:
  289.  
  290. NOT PRIME:  If this is returned, then the candidate is DEFINITELY not prime.
  291.  
  292. PRIME:      If this is returned, there is a 75% chance that the number is 
  293.             prime, and a 25% chance that it is not.
  294.             
  295.    Hence, there is a chance that a candidate is not actually a prime but the
  296. test indicates that it is. In this event, the "witness" is known as a "false
  297. witness". Now this, by itself, won't do. However, if we apply the test again
  298. with a new "witness", the chances of finding 2 false witnesses in succession
  299. are 0.25 * 0.25  or 1 chance in 16, and we can carry on finding new 
  300. witnesses, testing again and driving down the probability of error by a 
  301. further factor of 4. After 10 trials the chances of an error are 
  302. approximately 1 in 1 million. The number of Rabin tests to be applied is 
  303. held in a variable called nRabin. if you have been following this 
  304. introduction in detail, you will recall that we set nRabin to a value of 7
  305. in the Miscellaneous section F1.(This value is too low for serious work, but
  306. is good enough for demonstration purposes.) By default this value is set at
  307. 30 which will give very high quality results - many authorities recommend
  308. a value of 20. This test is implemented in assembler for maximum speed.
  309.    Returning now to the progress report on screen, each candidate is being
  310. examined in this way until a successful outcome is obtained. When a prime 
  311. has been found, it is written to file "df0:RSpublic/prime.data", and the 
  312. next item on the job-file started. This output file can be printed out using
  313. Miscellaneous F2 when all tasks are completed.
  314.    If you have entered the job-file as above, then the prime.data file will
  315. contain:
  316.    (a) 1 simple prime.
  317.    (b) 1 RSA-suitable prime.
  318.    (c) 1 safe prime.
  319.    What do these terms mean? A simple prime is just any prime number. The 
  320. first few are 2,3,5,7,11 etc. An RSA-suitable prime is a prime suitable for
  321. use with the RSA algorithm. Recall that {N} is the product of 2 primes 
  322. conventionally refered to as {p} and {q} ie N = p * q. When the RSA
  323. algorithm was first published, a method of attacking it was discovered which
  324. although feeble, can be countered by finding a {p} and {q} with a form
  325. such that:
  326.                   p  = 2.k'.p'  + 1
  327.                   p' = 2.k''.p''+ 1  ( ditto for q )
  328.  
  329.    Where k' and k'' are small primes and p, p', p'' are large primes. These
  330. recommendations are built into this package. The technique is to find a 
  331. simple prime to serve as p'', then try succesive low primes k'' until a 
  332. prime p' is found. If you watch the progress report, you will see k'' 
  333. increase apparently erratically. This occurs because p' is tested with a
  334. seive as a first stage, but this takes place so quickly that no attempt is
  335. made to display the results. When the seive is unable to eliminate the p',
  336. the k'' is displayed and Rabin's test is used on p'. Once a p' has been 
  337. found, the cycle is repeated to find a p which will be the RSA-suitable
  338. prime we require. One property of this technique is that the size of p 
  339. cannot be precisely controlled since the size of the "k's" is not known in
  340. advance. Later on when you use this module to set up an {N} value for 
  341. encryption purposes you will find that the {N} value that is output will be
  342. a few bits different from your input demand, and this is a result of the 
  343. technique described above.
  344.    A safe-prime was a name used in a text-book discussing problems in
  345. cryptology. I personally don't believe there to be anything "safe" about
  346. them - look upon it as just a label (and one not recognised elsewhere). 
  347. A safe-prime as defined here is a prime such that:
  348.  
  349.             p = 2.p' + 1       where p' is a simple-prime
  350.  
  351.    Such primes have (p-1)/2 primitive roots,(see nomenclature) and since
  352. there are a lot of them, it is a simple matter to find one. Such values are
  353. needed to set up the 3 128-bit linear congruential random number generators
  354. which provide a source of random bits for various low-grade tasks in this
  355. demonstration package.[L.C.G.'s are insecure for cryptographic work and
  356. IN THE FULL PACKAGE, BLUM-BLUM-SHUB (B.B.S.) GENERATORS ARE USED.]
  357. Safe-primes have a nasty property in that there are very large gaps
  358. containing none of them. If your starting point leaves you in such a gap,
  359. you may prefer to reset your Amiga rather than wait for it to exit.
  360.    The "cycle-time" refered to at the base of the screen is a rough
  361. estimate of the time to make one Rabin test. It is not better than about 10%
  362. or 2 secs whichever is greater.  Another big influence on total run time, is
  363. the distribution of primes themselves. For 250-bit numbers about 1 number in
  364. 173 is a simple prime and for 750-bit numbers about 1 in 520. (Safe primes
  365. are much rarer than this - these ratios are roughly squared in this case)
  366. Allowing for both cycle-time and distibution, the total run-time varies in
  367. proportion to the cube of the number of bits set (simple prime) (but with a
  368. wide scatter on individual runs).
  369.    The full software package can handle numbers of 2024 bits (approx 616 
  370. decimal digits) but you will be limited to 300 bits in MISCELLANEOUS F5 of 
  371. this demonstration system.
  372.  
  373.    If you have been working steadily through this introduction, you should
  374. by now be developing a feel for the trade-off between speed and security
  375. provided by the RSA algorithm. So by now you will be ready to set up your
  376. personal {N}, {e}, {d} parameters. In this text these 3 numbers are called a
  377. station and setting them up called station set-up. In regular computer
  378. parlance, the word station refers to the hardware of a terminal, but in this
  379. report, the word station refers to an individual users numbers. In an office
  380. with say 1 terminal and 20 users, we would say that there were 20 stations.
  381.    In setting up a station, we go through the following steps:
  382.    (a) Find {p}, {q} - 2 RSA-suitable primes.
  383.    (b) Find {N} = p * q.
  384.    (c) Find a value called {Phi}.
  385.    (d) Find values {d}, {e} which depend upon {Phi}
  386.    The values {N}, {d}, {e} have to be saved and the values {p}, {q}. {Phi}
  387. can be discarded. Since we assume that a potential eavesdropper can find out
  388. {N} and {e} without too much trouble, we must be aware that:
  389.    
  390.    If {N}, {e} are known by an eavesdropper (the normal case), then
  391.          knowledge of ANY ONE OF THE VALUES {p}, {q}, or {Phi}
  392.                 DESTROYS THE SECURITY OF THE RSA SCHEME.
  393.    
  394.   Consequently, we must take great care with the disposal of these 3 values.
  395. By default, in this package, these 3 values are not stored on disk,
  396. displayed on the VDU or output to the printer. ie they are only ever 
  397. stored in memory and these values can be destroyed by powering the machine
  398. down after station set-up is completed. However, for educational purposes,
  399. it is possible to over-ride this state of affairs by setting flag
  400. "FileStnData" to 1 in Miscellaneous F1. If you have been following this 
  401. introduction in detail, you will already have done this - if not set this
  402. flag to 1 now. When this flag is set, all 6 station numbers are written to
  403. file "RS:RSpublic/prime.data" in the order {p}, {q}, {N}, {Phi}, {d}, {e},
  404. and can be copied to the printer using Miscellaneous F2, when the station 
  405. set-up is complete.
  406.  
  407.    One final point should be made before we enter the station set-up 
  408. section. Setting up a new station destroys the old station parameters on
  409. your disk. Consequently, you must be working with a fresh copy of your disk
  410. so that you retain a copy of your old parameters. This is necessary for the
  411. following reasons:
  412.    (i) If you are changing your station numbers regularly as a security
  413. measure, there will always be someone who sends you messages using your 
  414. obsolete station values, and you will be unable to decrypt these messages
  415. if your old station values are lost. Incidentally this problem highlights
  416. the need for rigid procedures in distributing station numbers.
  417.    (ii) If you are archiving your incoming messages for future reference
  418. purposes, these messages must be stored in encrypted form and your old
  419. station parameters will always be needed to read these old messages.
  420.  
  421.    With this demonstration system, such considerations are not important and
  422. can be brushed aside. If you have real security problems, the demonstration
  423. system is not suitable.
  424.    So now armed with a freshly copied disk, we can now set up a new station
  425. so press F6. Before the main work starts the 3 128-bit pseudo-random number
  426. generators used for various low-grade tasks are reset. Each of these is set
  427. up by:
  428.    (a) Finding a safe-prime of suitable size as a modulus. (actually the 
  429.          size is in the range 112-128 bits) This is done automatically using
  430.          the old generators.
  431.    (b) Finding a multiplier which can be manually input or set 
  432.          automatically (just press <enter> when prompted). If you input the
  433.          multiplier yourself, it will be left or right shifted until it is
  434.          of a satisfactory size - in other words your input controls the 
  435.          most significant bits (they may not be immediately recognisable
  436.          since they may have been bit-shifted). This multiplier 
  437.          should be a primitive root, so it is tested and if it is not a 
  438.          primitive root then (multiplier+1), (multiplier+2) etc are tried
  439.          until a primitive root is found.
  440.  
  441.    When all 3 generators have been reset, (normally a few minutes only) the
  442. main station numbers are started upon. You will be prompted to input the 
  443. number of bits in {N}. This is the key variable which we have discussed
  444. above which dictates security level and encryption speed.
  445. FOR THE PURPOSE OF THIS DEMONSTRATION DISK, {N} IS LIMITED TO 350 BITS
  446. which provides only moderate security in commercial applications, and can
  447. be broken within hours by the national intelligence agencies.
  448.    Enter 330 now - this will suffice for demonstration purposes. 
  449.    Three prime-searching displays will now appear, 2 RSA primes and 1 
  450. simple prime, in that order.(these are {p}, {q} and {d} being found) (There
  451. are internal checks on the suitability of the {d} value found, and if these
  452. fail, the simple-prime section will be re-entered to find another {d}) Then
  453. {N}, {PHI} and {e} are found without display. After this you will be asked
  454. to input a password. It should be clear from the discussion above that all
  455. security in the RSA scheme relies on {d} being kept secret, and once it has
  456. been revealed all security vanishes. In an office environment, it is very
  457. easy to leave a disk lying about in a moments carelessness, with the
  458. possibility of security being compromised. If your security problems are
  459. severe, then you would have to adopt this assumption and reset your station
  460. parameters. However if your problems are less severe (ie unlikely to be
  461. attracting the interest of national agencies) it would be beneficial if the
  462. {d} value were hidden from a lesser opponent. The scheme that has been used
  463. is:
  464.    (a) The {d} value is exclusive-ORed with a random value and scatter 
  465.          loaded into a large (8k) array of random numbers.
  466.    (b) The precise details of this operation are controlled by a password
  467.          together with the 128-bit pseudo-random number generator in drawer
  468.          "RS:RSprivate".
  469.    (c) The password is turned into a number in this process and the 
  470.          following points about this should be noted.
  471.       (i) Upper-case and lower-case letters produce the same bit-patterns
  472.             in the number - hence a password of "FRED" will be just as 
  473.             effective in retrieving {d} as "fred".
  474.       (ii) The symbols "g", "G", "w", "W", "0" all produce no set bits in
  475.             the number. Hence passwords like "www" produce a number of zero
  476.             which would produce a crash.(such passwords are trapped and
  477.             refused)
  478.       (iii) All symbols on the light-tan keys are active and contribute to
  479.             the number, which means that passwords like "A  U" produces a
  480.             different number from "A U" (different number of spaces) 
  481.             ie all punctuation symbols have an effect.
  482.       (iv) Passwords of up to 160 characters are allowed, and 'crunched'
  483.            down to a suitable size. This means that every single character
  484.            must be correctly reproduced. It is very difficult to correctly
  485.            enter a 160-character password when it is not displayed on the
  486.            VDU and about 30 characters is a more practical upper limit.
  487.    This system could only be "broken" by a very sophisticated opponent
  488. - and not then when a B.B.S. generator is in use.
  489.    After your password has been input, the station set-up will take a 
  490. further few minutes to complete. Your new station parameters will be in
  491. "RS:RSpublic/Ne1.data" (holds {N}, {e}) and "RS:RSprivate/d1.data"
  492. (hides {d}). Since we have FileStnData set, all six station parameters have
  493. been copied to "RS:RSpublic/prime.data" file and so you can go into
  494. Miscellaneous F2 and have them printed out.
  495.  
  496.    At this point the {N},{e} pair may need to be circulated to other network
  497. members. In the full system, this is accomplished by copying {N} and {e}
  498. to a seperate disk "RSStation:" using Miscellaneous F4 and posting this to
  499. all members who can add in their own pair, copy it and then pass it on. On
  500. this demonstration system, there is no seperate disk, and using 
  501. Miscellaneous F4 adds the {N},{e} pair into a file 
  502. "RS:RSstation/Station.data". In order to circulate this, you will have to 
  503. use AmigaDOS to copy this file to a spare disk and circulate it in this way.
  504. This demonstration system permits only 2 stations in this file. For users
  505. who are just experimenting with the system, it is not necessary to 
  506. circulate your numbers in this way and you can just write messages to
  507. yourself. (hence skip Miscellaneous F4)
  508.  
  509.    Now we are ready to start encrypting messages. The "silent screen" 
  510. utility is intended for use when entering secure messages, but any word 
  511. processor package will do for demonstration purposes, so prepare a short
  512. message now. The following points should be observed in message 
  513. preparation:
  514.    (a)   Firstly consider the 2 Global variables <CharSet> and <AdapT>.
  515.        Two plaintext character sets are available with this package - the
  516.        MAXimum and MINimum character sets. 
  517.        
  518.        The MAXimum set consists of :
  519.        {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
  520.          !"£$%^&*()_+|-=\{}[]:@;#<>,.?/'~<space> + a few control symbols}
  521.        
  522.        These are the shifted/unshifted light-tan keys (+ the dark-tan key
  523.        at top left) on the Amiga.
  524.  
  525.        (This will cover just about all needs for normal commercial
  526.         correspondance. However, the set EXCLUDES the BREAK control-symbol 
  527.         (0x1b) which is used by word processing packages to force a printer
  528.         to print in 'itallic' or 'bold' or change-font etc. 
  529.                ALL SUCH PRINT ENHANCEMENT FEATURES SHOULD BE OMITTED.
  530.         Nothing serious will happen if they are included
  531.         - any unrecognised symbol is transmuted into a '?' symbol which may
  532.         spoil the appearance of a message but leaves the content unchanged.)
  533.         
  534.        The MINimum character set consists of :
  535.        {ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.? space + control symbols}
  536.  
  537.        (The cryptograms are about 15% shorter if this set is used which
  538.        will be useful if the cryptogram has to be manually entered at the
  539.        receivers end. 
  540.        NOTE : Adaptive compression is not used with this set.)
  541.        
  542.            No internal checks are done on texts before encryption. At
  543.        encryption, non-valid characters are changed to '?'. This means that
  544.        you should have a clear idea of the valid characters before entering
  545.        text. For instance, if the MINimum set is in use, lower-case symbols
  546.        are all changed to '?' ensuring any 'message' composed of them is
  547.        meaningless after decryption. 
  548.            These alphabets are compressed by a zero-order Huffman scheme as
  549.        a first stage in encryption. The compression can be made adaptive or
  550.        non-adaptive by setting global variable AdapT. Adaptive compression
  551.        results in a cryptogram about 10-15% shorter than when non-adaptive
  552.        compression is used. Both sender and receiver must have global
  553.        variables CharSet and Adapt set the same way or else garbage will be
  554.        the result. The default settings are MAXimum character set
  555.        + adaptive compression.
  556.    (b)    The two symbols <.s> or <.e> must not occur together in the file 
  557.        name. As will be explained below the decryption module searches for
  558.        the occurences of these to determine wether an encrypted file has
  559.        been signed or not. Hence file-names like <my.script> may cause
  560.        trouble. (the solution is simple - just rename your file)
  561.          
  562.    Encryption is a straightforward operation - just press F1 and respond as
  563. prompted. If this is your first entry into this section, do not select
  564. "signing" when requested. (It is not possible to 'sign' a cryptogram
  565. intended for your own archive or use - the two operations cancel one
  566. another out). If your input file was eg "df1:my.text" then the encrypted
  567. file will be eg "df1:my.text.1e001". As a message passes through
  568. encryption and decryption stages, the following appendages are added :
  569.  
  570.    <1> - the MAXimum plaintext alphabet was used by the originator.
  571.    <2> - the MINimum plaintext alphabet was used by the originator.
  572.     
  573.    <s> - this message has been signed.
  574.    <e> - this message has been encrypted.
  575.    <d> - this message has been decrypted.
  576.    <u> - this message has been un-signed.
  577.    
  578.    [D is any decimal digit below]
  579.    <eDDD> - DDD is the destination station reference number.
  580.    <sDDD> - DDD is the originators station reference number.[Optional]
  581.       NOTE : 3, any only 3 digits are entered here.
  582.       NOTE : As issued, this disk has a station reference number of 001.
  583.              After you set up your own set of station parameters,
  584.              and attempt to store these values in 'RSstation/Station.data'
  585.              for distribution, you will be prompted to input a new
  586.              station reference value and this is added to this file as well
  587.              as being stored in RSpublic/diskstnref. (In the full system,
  588.              RSstation/Station.data is a seperate disk which is posted to
  589.              other network members and the two values must agree. Hence:
  590.              FROM THIS MOMENT ON, YOUR PERSONAL STATION REFERENCE VALUE
  591.              SHOULD NOT BE CHANGED - it should stay 'attached' to you as
  592.              long as you remain in the network.) In this demonstration
  593.              system the same rule should be followed since only two
  594.              different station reference numbers are allowed in 
  595.              RSstation/Station.data and there is no deletion provision.
  596. thus:
  597.    my.text.1s012e987   implies : MAXimum alphabet/signed by station 12/
  598.                                 intended for station 987.
  599.    my.text.1s012e987du implies : as above but then decrypted and unsigned,
  600.                                  ie a recovered plaintext.
  601.    my.text.2e987       implies : MINimum alphabet/plain encryption
  602.                                 intended for station 987.
  603.    my.text.2e987d      implies : as above but then decrypted, another
  604.                                  recovered plaintext.
  605.  
  606.    The purpose of these appendages is:
  607.    (a) To prevent overwriting of the original message.
  608.    (b) To indicate the status of intermediate files.
  609.    (c) To pass over to the receiver details which he needs for a successful
  610.          decryption. (If the decryption section finds non-standard file
  611.          appendages, then the information has to be manually input in 
  612.          response to prompts.)
  613.    IN THIS DEMONSTRATION SYSTEM, THE INTERMEDIATE FILE GENERATED DURING
  614.    SIGNING (eg my.text.1s012) IS ALSO WRITTEN TO THE DIRECTORY HOLDING
  615.    YOUR ORIGINAL MESSAGE. THIS FILE IS INSECURE (the plaintext can be
  616.    recovered from it by use of the public-key). IN THE SECURE SYSTEM, IT
  617.    IS HELD IN ram: AND DESTROYED AFTER POWERING DOWN.
  618.  
  619.    Your encrypted files can now be printed out using F3 - F3. Note that it
  620. is a straightforward text-file consisting of symbols 
  621.                0-9, A-F, + spaces (+ ASCII control symbols)
  622. and hence is suitable for printout or modem transmission.
  623.    You will also notice that the file is roughly 1.5-times longer than your
  624. original file.
  625.    Decryption is also straightforward. Just press F2 and respond to the 
  626. prompts. You might like to experiment with erroneous passwords to convince
  627. yourself that it is impossible to retrieve {d} successfully without a
  628. correct password. Your decrypted file will be in file "df1:my.text.1e001d"
  629. which can be printed out and will be identical to your original file. If it
  630. is not then your original text contained non-valid characters whose
  631. presense will be revealed by "?" symbols appearing in strange places.
  632.  
  633.    We can now do a signed encryption. To do this go through the following
  634. steps:
  635.    (a) Make a second copy of the demonstration disk.
  636.    (b) Run Miscellaneous F6 (station set-up) on both disks seperately
  637.          keeping note of the passwords.
  638.    (c) Copy {N},{e} to the RS:RSstation/Station.data file on the first disk
  639.          using Miscellaneous F4 - keeping note of the station reference
  640.          number you choose.
  641.    (d) Use AmigaDOS to copy RS:RSstation/Station.data across from disk 1 to
  642.          the corresponding file on disk 2.
  643.    (e) Add the {N},{e} values on disk 2 into file RS:RSstation.Station.data
  644.          using Miscellaneous F4 - use a different station reference number
  645.          or else the first {N},{e} pair will be overwritten. The file will
  646.          now hold both pairs of {N},{e}.
  647.    (f) Copy RS:RSstation.Station.data back from disk 2 to disk 1 (AmigaDOS).
  648.    (g) Write some 'message' on disk 1 for disk 2, giving disk 2's station
  649.          reference number when requested.
  650.    (h) The cryptogram can be copied across to disk 2 (AmigaDOS) 
  651.          - simulating transmission.
  652.    (i) Switch to disk 2, and decrypt the message. You might like to try
  653.          this stage with standard and with non-standard appendages. In the
  654.          non-standard case you will be prompted for encryption details.
  655.  
  656.    Thats all Folk's! The only section that we have not visited is
  657. Miscellaneous F3, which is not much use until such time as "Station.data"
  658. is part-filled by using F4. Both of these sections are self-evident.
  659.  
  660.    The principal assembler routine at the heart of this software has been 
  661. timed at 7 times faster on the Amiga 1200 than on an Amiga 600.(the extra
  662. length of the multiply and divide instructions play a big part in this).
  663. The Amiga 4000 should provide a 4-5 speed gain above an Amiga 1200.
  664.  
  665.                METHODS OF ATTACKING THE R.S.A. ALGORITHM
  666.                =========================================
  667.       [Some of these attacks apply to any encryption technique]
  668.       
  669.    The subject of cryptanalysis has certain formal definitions used in
  670. discussions of the subject. These are :
  671.  
  672. Participants :
  673.    (1) Alice and Bob are the 2 people trying to communicate secretly.
  674.    (2) Eve is an eavesdropper. Eve is passive (does not react to any
  675.          'cracked' messages) and tries very hard to remain undetected.
  676.    (3) Mallet is a malicious intruder. His objectives may include fraud, 
  677.          spreading disinformation etc etc. Mallet is active, and will be 
  678.          detected once he makes his move - once he has defrauded a company
  679.          he has to run for it. Mallet is generally an Eve in the early
  680.          stages of an operation. 
  681.    [The distinction between active and passive is fuzzy in real life. Most
  682.     Eve's will respond actively when the payoff is high enough :- but the
  683.     response will be 'engineered' to lead suspicion away from Eve.]
  684.       If Mallet is forced to be an Eve by a counter-intelligence department
  685.    (ie his objective of company fraud is prevented) then this is success at
  686.    least as far as the accounts department is concerned. Success against Eve
  687.    is harder to achieve and 'damage-limitation' is the order of the day.
  688.    If Alice changes her R.S.A. parameters every day,(or hour), then Eve can
  689.    only gain partial intelligence even if she use one of the methods below
  690.    to achieve a break.
  691.    
  692. Methods of Attack :
  693.    This can be a large list, but for our purposes the following suffice.
  694.    (1) Ciphertext only. This is the method known to the general public. A
  695.          wire-tapper collects cryptograms and rushes them round to a
  696.          bespectacled mathematician who feeds them to his supercomputer, and
  697.          within moments out pops the plaintext. Such a method is hopeless
  698.          against the R.S.A. if Alice knows her business.
  699.    (2) Known plaintext attack. In this method, Eve (or Mallet) trick Alice
  700.          into transmitting a message written by her. This is usually done by
  701.          allowing important information to 'fall' into Alice's possession.
  702.          Such a message has zero-entropy (see nomenclature) to Eve and gives
  703.          her a good analytical position. This attack is irrelevant to the
  704.          R.S.A. scheme - ENcryption details are openly published: only
  705.          DEcryption details are secret - hence there is nothing to uncover.
  706.    (3) Chosen Plaintext attack. This is an extension of (2) whereby if the
  707.          first trial fails, a modified text is tried until a break occurs.
  708.          With the R.S.A. scheme, it is conceivable that say 10,000,000
  709.          common (low-entropy) messages could be encrypted and stored by Eve
  710.          and then compared with actual cryptograms. The counter to this is
  711.          to use various entropy-enhancing features with the R.S.A. such as
  712.          Initiallising Vectors and padding (see nomenclature for details).
  713.    (4) Differential analysis attack. This was only made public in 1990 by
  714.          Biham and Shamir. In this Eve compares ciphertexts which originate
  715.          from nearly identical plaintexts. No success against the R.S.A.
  716.          from this technique has yet been published, but anyway I.V.'s and
  717.          padding will counter it.
  718.    (5) Illegal methods. These include threats, bribery, theft, bugging the
  719.          machine to record key-strokes or the plaintext en-route to the
  720.          printer or analysing acoustic emmisions from the printer. Damage
  721.          limitation is the order of the day. It is useful to have a
  722.          procedure in place enabling threatened individuals to reveal their
  723.          plight without the sky falling on them. Knowledge of a
  724.          blackmailing operation, enables a cordon-sanitaire to be put
  725.          around the target. Illegal methods are far and away the
  726.          easiest way of breaking into an R.S.A. scheme and highlight the
  727.          fact that any encryption scheme can only be a part of overall
  728.          security policy.
  729.    (6) Trickery. 
  730.           (a) If Eve can induce Alice to 'sign' a message which she has
  731.          not checked, she may be able to retieve {d} in some circumstances.
  732.          This is the electronic equivalent of signing a blank cheque, and
  733.          should never be done.
  734.           (b) If Mallet can break into the telephone network on the line
  735.          between Alice and Bob, he might be able to masquerade as the other
  736.          to each of them. This wont work if a public-key data base is in
  737.          use but can work if Alice and Bob are stangers and need to
  738.          exchange public-keys as a first stage in setting up a session.
  739.          This is the so called man-in-the-middle attack. A technique to
  740.          force Mallet to become an Eve has been published, but the best
  741.          solution is to use pre-arranged public-keys. Non-wire
  742.          communication methods, such as cellular radio or satellite systems
  743.          are very hard to break into in this way, even for national
  744.          agencies.
  745.    (7) Number theory methods.
  746.           (a) Factorise {N} - this has been discussed above.
  747.           (b) Calculate a logarithm (mod composite). This is not discussed
  748.          but is as hard as (a).
  749.           (c) Use of {N},{e} and a ciphertext block [C]. [A bit 'tuff-sums'
  750.          this so you may prefer to skip this section secure in the
  751.          knowledge that the attack and its counter are well understood, and
  752.          the attack will fail] You will need to be familiar with the number
  753.          theory section (at the end) to understand this :-
  754.          
  755.          Suppose an analyst performs :-
  756.                   C[1] = <C[0]^e> N   over and over checking each new C[]
  757.                                         to see if a C[i+1] is plaintext.
  758.            hence  C[2] = <C[1]^e> N = <C[0]^(e^2)> N
  759.            and    C[i] = <C[0]^(e^i)> N
  760.            Hence if ever e^i = d = e^(-1)(mod LAMBDA(N)) then a break will
  761.                                                          have occured.
  762.            This occurs when k.LAMBDA(LAMBDA(N)) - 1 = i (and k=1 will do)
  763.            The counter to this attack i to ensure
  764.                       LAMBDA(LAMBDA(N))         is very large.
  765.            Recall that in this package N = p.q and that p and q are of the
  766.            form   p = 2.k'.p' + 1               q = 2.l'.q' + 1
  767.                   p'=2.k''.p''+ 1               q'=2.l''.q''+ 1
  768.            where p,p',p'',q,q',q'' are all large primes and
  769.            k',k'',l',l'' are small (different) primes ( < about 14 bits )
  770.  
  771.            Hence since LAMBDA(N) = 2.k'.l'.p'.q'   then
  772.            
  773.             LAMBDA(LAMBDA(N)) = lcm[PHI(k'),PHI(l'),PHI(p'),PHI(q')]
  774.             
  775.            The exact value of this expression depends on the make-up of 
  776.            k' and l' but we can say
  777.                LAMBDA(LAMBDA(N)) = K.2.p''.q''   where K>2
  778.            Now since the k's and l's are <= about 14 bits then
  779.                bitsize (p''.q'') >= bitsize (N) - 58  
  780.            Hence if N = 200 digits (660 bits) then
  781.                bitsize (p''.q'') approx= 600 bits and p''.q'' is the number
  782.            of iterations an analyst has to perform to succeed in this
  783.            attack.
  784.            To realise how difficult this is, the number of molecules in the
  785.            whole known universe - out to 30 billion light years - is a
  786.            number with about 280 bits in binary. In fact so long as
  787.            p''.q'' > 100 bits (ie N > 160 bits [50 decimal digits]) this 
  788.            attack is hopeless.
  789.           (d) Find PHI(N) or LAMBDA(N) and then find {d} from 
  790.                e.d = k.LAMBDA(N) + 1 or (k.PHI(N)) + 1). 
  791.          These can only be found after {N} has been factorised which may
  792.          take a few millenia, but, lets look on the bright side, once p and
  793.          q are known, d is easy to find.
  794.             
  795.       #--------------------------------------------------------------#   
  796.  
  797.                            NOMENCLATURE
  798.                            ============
  799. composite : A non-prime. Hence a composite can be expressed as the product
  800.             of at least 2 primes.
  801.             
  802. encrypt : The process of transforming a message to an unintelligible form.
  803.           (see decrypt). In the RSA scheme, the recipients public-key is
  804.           needed to accomplish this. Thus if a message has to be 
  805.           transmitted to say 7 different people, then 7 seperate 
  806.           encryptions will be needed. Also since the public-keys are not
  807.           secret in the RSA scheme, a third-party could use the public-keys
  808.           to forge a message.("signing" stops this possibility)
  809.           
  810. entropy : A measure of whatever is unknown about an event or message.
  811.           Entropy is measured in binary bits, and depends upon the number of
  812.           outcomes and the probability of each outcome. Events which are
  813.           certain have zero entropy and events which have uncertain outcomes
  814.           have high entropy. Some examples might help :
  815.           Event : The sun will rise tomorrow morning :- entropy zero.
  816.              (the sun will definitely rise tomorrow morning, and if it 
  817.              doesnt, no one will be worrying about the damage done to
  818.              applied maths)
  819.           Event : The outcome of a fair coin-toss : entropy 1 bit.
  820.              (only 2 outcomes are possible and these can be represented by
  821.               1 bit being set or not-set)
  822.           Event : The outcome of a 32 equal-horse race : entropy 5 bits.
  823.              (2^5 = 32 can represent each possible outcome)
  824.           Event : The outcome of a 32 unequal-horse race : entropy < 5 bits.
  825.              (More complicated this. The result depends on the odds
  826.               of each horse winning. Consider 2 extreme cases :
  827.               (i) 1 entrant is a Derby winner, the others are donkeys from
  828.                   Blackpool beach. The entropy is nil.
  829.               (ii) All entrants are equally likely to win. This is the 5-bit
  830.                   entropy case above and is the maximum-entropy case.
  831.           Event : Any message of 80 characters : entropy 0-100 bits(approx).
  832.              (If the message is in ASCII format, it will need 640 bits to
  833.               store it. However not all letters are equally likely - 'e' is
  834.               much more likely than 'z' - and by comparison with the
  835.               unequal-horse race - the entropy per letter will be much less
  836.               than 8 bits typically 3.7 bits. In fact careful measurements
  837.               of English text indicate that the entropy per character is
  838.               only about 1.2 bits. As evidence of this, consider the
  839.               following incomplete sentence:
  840.               T-- ra-- -- Sp--n -all- ------ on th- p---n
  841.               With a little guesswork, we conclude that the sentence is:
  842.               The rain in Spain falls mainly on the plain
  843.               Put simply: many letters are superfluous (zero-entropy!)
  844.           The transmitter of secure messages must try to keep the entropy
  845.           of his messages high, while an eavesdropper is always hoping that
  846.           he can find a low entropy message. One way of attacking
  847.           cryptographic systems is to 'feed' messages to Alice (possibly
  848.           using the newspapers) and then monitor her cryptograms. Such
  849.           messages have zero, or low, entropy to Eve. If Alice is unskilled,
  850.           she might write low-entropy messages out of ignorance. Such
  851.           messages include the letter headings and tailings of commercial
  852.           correspondance - the company name,address,'Dear Sirs' formalities
  853.           etc are all zero-entropy; the letter reference number will have
  854.           low entropy; and if the text is right-justified, may include
  855.           several hundred 'space' symbols (low-entropy).
  856. decrypt : The process of transforming an unintelligible message back to an
  857.           intelligible state.(see encrypt) In the RSA scheme, the recipients 
  858.           private-key is needed to accomplish this. The private-key must be
  859.           kept secret - all secrecy in the RSA scheme relies on this. In 
  860.           this implementation the private-key can only be accessed by entry
  861.           of a password.
  862.           
  863. Initiallisation Vector : This is an entropy-enhancing technique useful with
  864.       low-entropy messages or when unskilled operatives are using a network
  865.       (see also padding). In this method, the first number block is all
  866.       random bits (from a secure generator). This is encrypted and
  867.       transmitted. The real message starts with the second block which is
  868.       exclusive-or'd with the first block - this is just a reversible
  869.       process which makes the entropy of the second block greater than that
  870.       of the first block (very high). This is then encrypted and
  871.       transmitted. The receiver can decrypt this system easily so long as
  872.       he knows that an I.V. is in use. (The easiest way to organise this is
  873.       for all network members to agree to use I.V.'s.)
  874.       Third and subsequent blocks are treated in a similar way.
  875.       This technique is not supported by this demonstration system.
  876.           
  877. key : The information needed to encrypt/decrypt a message. Conventionally
  878.       one key does both functions but in the RSA scheme a "public-key" is
  879.       used for encryption and a "private-key" for decryption. Public-keys
  880.       can be openly distributed to anyone who asks for them without loss of
  881.       security.
  882.  
  883. originator : The person who wishes to transmit a message to a recipient.
  884.  
  885. padding : This is an entropy-enhancing technique (see also Initiallisation
  886.           Vector). In this the first (or last), say, 32 bits of a block are
  887.           filled with random bits. Even if the entropy of the message was
  888.           zero, the entropy of a padded block will be >= the entropy of the
  889.           padding ie about 32 bits leaving an analyst with a tough problem.
  890.           The technique can be extended to 64 or even 96 bits if needed, but
  891.           the encryption rate (chars/sec) drops off in proportion. This
  892.           technique is not supported by this demonstration system.
  893.           
  894. private-key : The information needed to decrypt a message. In the RSA 
  895.               scheme the private-key is a single very-large number refered
  896.               to as {d} (for decryption exponent).
  897.  
  898. public-key  : The information needed to encrypt a message. This is 
  899.               invariably the recipients public-key which may be published
  900.               in a document like a telephone directory, but in this
  901.               implementation will be found from in disk-file "Station.data".
  902.               If you are yourself the recipient (adding to a personal
  903.               secure archive) then the public-key will be available in
  904.               disk-file "RS:RSpublic/Ne1.data". In the RSA scheme the 
  905.               public-key consists of 2 very large numbers {N} and {e}.
  906.  
  907. recipient : The only person who can decrypt an incoming encrypted message.
  908.             Equivalently, the person to whom the message is directed.
  909.             
  910. signing : The process by which an originator identifies a message uniquely
  911.           with himself. In the RSA scheme, signing is a similar process to
  912.           encryption but using {d} (the private key) as the encryption
  913.           exponent rather than {e}. A signed message is not secure by 
  914.           itself and must be followed immediately by a standard encryption
  915.           to make it secure. The resulting signed and encrypted message
  916.           can only be decrypted by the intended recipient, who can then be 
  917.           completely certain of the originators identity. A signed message
  918.           cannot be forged by a third party intent on mischief. Hence
  919.           a recipient receiving instructions involving high-risk to himself
  920.           might want to insist on the instructions being signed as proof of
  921.           the originators identity. Signing is a very strong concept
  922.           cryptographically. There is every hope that it will be accepted
  923.           in law shortly as contractually binding. The concept of "signing"
  924.           opens up a whole new field of use for cryptology beyond the
  925.           obvious secret communication one. Using signed messages, "deals"
  926.           or "contracts" can be struck instantly between any two parties
  927.           anywhere on the planet without the need for signed and witnessed
  928.           documents. An all-electronic contract would consist of a signed
  929.           message of proposal and a reply of a signed message of acceptance.
  930.           Such all-electronic dealing cannot be forged by a third party and
  931.           neither signatory could deny that a deal had been struck at some
  932.           future date. Various protocols also exist for getting such
  933.           signed contracts electronically 'witnessed' by neutral third
  934.           parties in a manner that mimics witnessing of paper contracts.
  935.           
  936. primitive-root : A number (a) such that the set of numbers
  937.                  {<a> mod p, <a*a> mod p, ......<a^(p-1)> mod p } [p prime]
  938.                  is the set
  939.                   {1, 2, 3, ........(p-1)} permutated (ie shuffled up).
  940.           
  941.       #---------------------------------------------------------------#
  942.  
  943. A LITTLE NUMBER THEORY
  944. ======================
  945. Modular Arithmetic
  946. ------------------
  947.    The result of the operation   a mod b  is the remainder resulting from
  948. subtracting (or adding) b from a until 0<=a<=(b-1)
  949. Hence:
  950.          5 mod 3  = 2
  951.         -1 mod 3  = 2
  952.          8 mod 4  = 0   etc.
  953.    Clearly the result is always in the range     0.......(b-1).
  954.  
  955.    More complex operations can be tackled by evaluating "a" first and then
  956. finding   a mod b   as above.
  957. Hence:
  958.          <7cubed> mod 3  =  7*7*7 mod 3  =  343 mod 3 = 1
  959.          
  960.    In this text we shall use brackets <> to delineate the boundaries of the
  961. modular operation, hence:
  962.          <5> 3   means   5 mod 3 = 2.
  963.    The folloowing formulae are useful in evaluations :
  964.       <x + y> = <<x> + <y>>
  965.       <x - y> = <<x> - <y>>
  966.       <x * y> = <<x> * <y>>
  967.    Hence :
  968.    62^50 mod 5 = <62 * 62 ..(50 times) ..62> 5
  969.                = < 2 *  2 ..(50 times) .. 2> 5
  970.    substituting <2^10> 5 = <1024> 5 = 4 we get
  971.                = <4 * 4 * 4 * 4 * 4> 5 = <1024> 5 = 4
  972.  
  973.    Shortly, we shall need to distinguish between different sets of integers.
  974. In particular, we shall need the following 3 sets :
  975.    The set Z   => the set of all integers.
  976.    The set Zn  => the set of all integers which can result from the mod 
  977.                   operation defined above. Clearly Z3 = {0,1,2}
  978.                   Note that the order of Zn (the number of elements in Zn)
  979.                   is equal to n.
  980.    The set Zn* => the subset of Zn of those elements of Zn which are
  981.                   mutually prime to n. Z6* = {1,5}. Note that 0 is not in
  982.                   this set since   gcd(0,n) = n.
  983.                   (gcd means greatest common divisor, and 2 numbers are
  984.                       mutually prime when gcd(a,b)=1).
  985.                   The order of Zn* has a special symbol - PHI.
  986.                    
  987.    PHI can be calculated from the following :
  988.    (i)   PHI(p)   = p-1            (p any prime)
  989.    (ii)  PHI(p^n) = (p-1).p^(n-1)
  990.    (iii) if N = p^e.q^f...        (p,q.. prime)
  991.             then PHI(N) = PHI(p^e).PHI(q^f)......
  992.  
  993.    eg PHI(252) = PHI(2^2.3^2.7)
  994.                =     2  .6  .6   =   72 
  995.    
  996.    The theory above is of particular relevance in the following 3 theorems:
  997.    
  998.    (i)   Fermat's little theorem (for a an element of Zn)
  999.                   a^(p-1) = 1 (mod p)
  1000.  
  1001.          eg for a = 3, and p = 7
  1002.          then <3^6> 7 = <9^3> 7 = <2^3> 7 = <8> 7 = 1
  1003.    (ii)  Eulers theorem extends Fermat's theorem (which applies to primes)
  1004.             to composites :
  1005.                   a^PHI(n) = 1 (mod n)  (for a an element of Zn*)
  1006.  
  1007.           eg for a = 5, and n = 6 ,
  1008.           then PHI(6) = 2 and Euler's theorem gives 5^2 = 25 = 1 (mod 6)
  1009.             From Euler's theorem we can get :
  1010.             a^PHI(n) * a^PHI(n) = a^(2.PHI(n)) = 1 * 1 = 1 (mod n)
  1011.             and by extension a^(k.PHI(n)) = 1   mod n
  1012.             and multiplying this by a gives
  1013.  
  1014.                a^(k.PHI(n) + 1) = a   mod n     *** key relation ***
  1015.  
  1016.          NOTE : This last statement applies even when 'a' is in Zn but not
  1017.                 in Zn*. eg a = 3, n = 6, PHI(6) = 2,
  1018.                 then <3^3> 6 = <3^5> 6 = etc = 3 
  1019.                  but Euler's theorem fails with these numbers :
  1020.                    ie   <3^2> 6 = 3 
  1021.                 So the key relation is valid for all values, but Eulers
  1022.                 theorem only works for elements of Zn*.
  1023.    (iii) Charmichaels Theorem provides a stronger statement than Euler's
  1024.          theorem :
  1025.                   a^LAMBDA(n) = 1 mod n
  1026.          LAMBDA(n) can be calculated from :
  1027.          if N = 2^a.p^e.q^f......
  1028.          
  1029.          then LAMBDA(2^a) = 2^(a-1)  if a<3
  1030.                      or   = 2^(a-2)  if a>=3
  1031.          and LAMBDA(N) = lcm [ LAMBDA(2^a), PHI(p^e), PHI(q^f)......]
  1032.          (where  lcm => lowest common multiple)
  1033.  
  1034.          eg LAMBDA(28) = lcm [ LAMBDA(2^2), PHI(7) ]
  1035.                        = lcm [ 2^1 , 6 ]
  1036.                        = lcm [ 2, 6 ]    =  6
  1037.          the following relate LAMBDA to PHI :
  1038.             (a) LAMBDA(n) <= PHI(n)
  1039.             (b) LAMBDA(n) divides into PHI(n) without remainder.
  1040.             (c) LAMBDA(p.q) <= PHI(p.q) / 2     (p,q both primes)
  1041.       The formula for LAMBDA above is about the easiest thing to get wrong
  1042.    that I know of. Check your grasp by finding the following :
  1043.                 LAMBDA(LAMBDA(103)) = 16
  1044.                 LAMBDA(LAMBDA( 17)) =  4
  1045.                 LAMBDA(LAMBDA( 31)) =  4
  1046.  
  1047.       The R.S.A. algorithm relies principally on Eulers theorem and the 
  1048.    ability to find 2 numbers such that :-
  1049.    
  1050.                e.d = k.PHI(N) + 1
  1051.                
  1052.       Having found a pair of numbers such as {e} and {d} then from Eulers
  1053.    theorem for any 'a' (in Zn)
  1054.    
  1055.                a ^ (e.d) = a  (mod  N)   
  1056.                
  1057.       and we have a simple process which recovers the number we started out
  1058.    with. The expression above can be rewritten :
  1059.    
  1060.                (a ^ e) ^ d = a  (mod N)
  1061.                
  1062.    which suggests that if we form               
  1063.  
  1064.                C = a ^ e  (mod N)      we can recover a from C :
  1065.                a = C ^ d  (mod N)
  1066.                
  1067.       Now all this is very interesting, but is no proof of cryptographic
  1068.    merit. We have merely explained one more method of transmuting a message
  1069.    {a} into a cryptogram {C} and then recovering it. There are thousands of
  1070.    such methods known. Why should this be superior to any other? This is a
  1071.    big question, which cannot be pursued here. Suffice it to say that it
  1072.    has withstood all assault so far.
  1073.    
  1074.       #-------------------------------------------------------------#
  1075.